Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace JPC.Medialibrary.DAL
	#Region "Tables Struct"
	Public Partial Structure Tables
		Dim x As Integer
		
		Public Shared  Album As String = "Albums"
        
		Public Shared  Artist As String = "Artists"
        
		Public Shared  EpisodeViewHistory As String = "EpisodeViewHistory"
        
		Public Shared  Playlist As String = "Playlists"
        
		Public Shared  PlaylistSong As String = "PlaylistSongs"
        
		Public Shared  Song As String = "Songs"
        
		Public Shared  SongTag As String = "SongTags"
        
		Public Shared  Tag As String = "Tags"
        
	End Structure
	#End Region
	#Region "Schemas"
	
Public Class Schema
		
		Public Shared ReadOnly Property Album As TableSchema.Table
			Get
				Return DataService.GetSchema("Albums","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property Artist As TableSchema.Table
			Get
				Return DataService.GetSchema("Artists","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property EpisodeViewHistory As TableSchema.Table
			Get
				Return DataService.GetSchema("EpisodeViewHistory","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property Playlist As TableSchema.Table
			Get
				Return DataService.GetSchema("Playlists","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property PlaylistSong As TableSchema.Table
			Get
				Return DataService.GetSchema("PlaylistSongs","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property Song As TableSchema.Table
			Get
				Return DataService.GetSchema("Songs","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property SongTag As TableSchema.Table
			Get
				Return DataService.GetSchema("SongTags","Medialibrary")
			End Get
		End Property
        
		Public Shared ReadOnly Property Tag As TableSchema.Table
			Get
				Return DataService.GetSchema("Tags","Medialibrary")
			End Get
		End Property
        
	End Class
	#End Region
    #Region "View Struct"
    Public Partial Structure Views
		Dim x As Integer
		
    End Structure
    #End Region
	#Region "Query Factories"
	Public Partial Class DB
		Private Sub New()
		End Sub
		Public Shared _provider As DataProvider = DataService.Providers("Medialibrary")
		Private Shared _repository As ISubSonicRepository
		Public Shared Property Repository() As ISubSonicRepository
			Get
				If _repository Is Nothing Then
					Return New SubSonicRepository(_provider)
				End If
				Return _repository
			End Get
			Set
				_repository = Value
			End Set
		End Property
		Public Shared Function SelectAllColumnsFrom(Of T As {RecordBase(Of T), New})() As [Select]
			Return Repository.SelectAllColumnsFrom(Of T)()
		End Function
		Public Shared Function [Select]() As [Select]
			Return Repository.Select()
		End Function
		Public Shared Function [Select](ParamArray ByVal columns As String()) As [Select]
			Return Repository.Select(columns)
		End Function
		Public Shared Function [Select](ParamArray ByVal aggregates As Aggregate()) As [Select]
			Return Repository.Select(aggregates)
		End Function
		Public Shared Function Update(Of T As {RecordBase(Of T), New})() As Update
			Return Repository.Update(Of T)()
		End Function
		Public Shared Function Insert() As Insert
			Return Repository.Insert()
		End Function
		Public Shared Function Delete() As Delete
			Return Repository.Delete()
		End Function
		Public Shared Function Query() As InlineQuery
			Return Repository.Query()
		End Function
        
	End Class
	#End Region
End Namespace
 
#Region "Databases"
Public Partial Structure Databases
	Dim x As Integer
	
	Public Shared Medialibrary As String = "Medialibrary"
    
End Structure
#End Region
